package com.gaga.metadata.function;

import com.gaga.metadata.common.enums.DbOperatorType;
import com.gaga.metadata.common.enums.FilterFiledType;
import com.gaga.metadata.common.enums.ModelFilterType;
import com.gaga.metadata.common.enums.SqlFunctionType;
import com.gaga.metadata.entity.base.BaseColumn;
import com.gaga.metadata.entity.base.BaseFilter;

import java.util.List;

/**
 * @author liujia
 * @version 1.0
 * @date 2022/10/14 14:19
 */
public abstract class AbstractFunctionProvider<T extends BaseFilter, S extends BaseColumn> {

    /**
     * 具体的处理方法
     *
     * @param column
     * @return
     */
    public abstract List<T> handler(S column);

    public void init() {

    }

    /**
     * 封装Symbol 过滤器
     *
     * @param dbOperatorType
     * @return
     */

    public T getSymbolFilter(T t, DbOperatorType dbOperatorType) {
        return getSymbolFilter(t, dbOperatorType.getCode());
    }

    public T getSymbolFilter(T t, String oper) {
        t.setType(ModelFilterType.symbol);
        t.setOper(oper);
        return t;
    }

    /**
     * 封装function 过滤器
     *
     * @param sqlFunctionType
     * @return
     */

    public T getFunctionFilter(T t, SqlFunctionType sqlFunctionType) {
        return getFunctionFilter(t, sqlFunctionType.getCode());
    }

    public T getFunctionFilter(T t, String functionString) {
        t.setType(ModelFilterType.fun);
        t.setName(functionString);
        return t;
    }

    /**
     * 封装列 过滤器
     *
     * @param column
     * @return
     */
    public T getColumnFilter(T t, S column) {
        return getColumnFilter(t, column, column.getName());
    }

    public T getColumnFilter(T t, S column, String columnName) {

//        if (StringUtils.isBlank(columnName)) {
//            return getColumnFilter(t, column);
//        }
        t.setType(ModelFilterType.column);
        t.setColumnName(columnName);
        t.setLinkTableNameOrAliasName(column.getLinkTableNameOrAliasName());
        return t;
    }

    /**
     * 封装value 过滤器
     *
     * @param value
     * @return
     */
    public T getValueFilter(T t, String value) {
        return getValueFilter(t, value, null);
    }

    /**
     * 封装value 过滤器
     *
     * @param value
     * @return
     */
    public T getValueFilter(T t, String value, FilterFiledType filedType) {
        t.setType(ModelFilterType.value);
        t.setValue(value);
        t.setFieldType(filedType);
        return t;
    }


}
